/**
 * JAVACC DEMO 1.0
 */
package com.apache.portal.weixin.service;

import com.apache.portal.weixin.core.common.LoadService;
import com.apache.portal.weixin.entity.BaseVo;
import com.apache.portal.weixin.entity.InfoVo;
import com.apache.portal.weixin.entity.recv.WxRecvMsg;
import com.apache.portal.weixin.entity.recv.WxRecvTextMsg;
import com.apache.portal.weixin.entity.send.WxSendMsg;
import com.apache.portal.weixin.entity.send.WxSendTextMsg;
import com.apache.uct.common.ToolsUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * description:
 *
 * @author dyhou 创建时间：2017-3-2
 */
public class TextServiceImpl extends AbstractService {

    /**
     * TODO 简单描述该方法的实现功能（可选）.
     */
    public Object execute(BaseVo vo) throws Exception {

        WxRecvMsg wxRecvMsg = vo.getWxRecvMsg();
        WxRecvTextMsg event = (WxRecvTextMsg) wxRecvMsg;
        WxSendMsg sendMsg = null;
        String menuKey = ToolsUtil.getInstance().getValueByKey("menu_key");
        if (menuKey.indexOf(event.getContent()) != -1) {
            List<InfoVo> list = new ArrayList<InfoVo>();
            list.add(getInfoVoFromProp(event.getContent()));
            sendMsg = LoadService.getInstance().getTools().builderSendByRecv(wxRecvMsg);
            sendMsg = getInfos(list, sendMsg);
        } else {
            String content = "XX呼唤";
            String type = "all";
            String msgtype = "text";
            /**
             * 发客户服消息（格式
             */
            //String openId = "\"oPm2at8o3rd-ZNiRYJ0LFzeFOPI8\"";
            //			String content = "\"title\":\"消息回复\",\"description\":\"XX呼唤\",\"url\":\"\",\"picurl\":\"\"";
            //			String content = "XX呼唤";
            //type="crm";
            //msgtype = "text/news";
            /**
             * 指定openId,至少两个
             */
            //			String openId = "\"oPm2at8o3rd-ZNiRYJ0LFzeFOPI8\",\"oPm2at8kxAcZfiXYuKt2zPLEm544\"";
            //			String content = "XX呼唤";
            //type="openId";
            /**
             * 群发
             */
            //			String openId = "";
            //			String content = "XX呼唤";
            //type="all";

            LoadService.getInstance().getTools()
                    .sendMsg("\"oPm2at8o3rd-ZNiRYJ0LFzeFOPI8\"", content, type, msgtype);//推送给服务生
            sendMsg = LoadService.getInstance().getTools().builderSendByRecv(wxRecvMsg);
            sendMsg = new WxSendTextMsg(sendMsg, "您输入的是[" + event.getContent() + "]信息吗?");
        }
        return sendMsg;
    }
}
